<?php 
	require_once("init.php");  
?>

<?php
  // New topics
	$qMyTopic = mysql_query("
    SELECT 
			t.*,
			c.name AS categoryName
		FROM topics t
			INNER JOIN categories c ON t.categoryId = c.categoryId
    WHERE t.topicId = ".$_GET["id"]."
  ");
	
  while ($row = mysql_fetch_array($qMyTopic)) {
		$totalVotes = $row["answer1Votes"] + $row["answer2Votes"];
		if ($totalVotes > 0) {
			$answer1Percent = $row["answer1Votes"]/$totalVotes * 100;
			$answer2Percent = $row["answer2Votes"]/$totalVotes * 100;
		} else {
			$answer1Percent = 0;
			$answer2Percent = 0;
		}
		$answer1Class = "";
		$answer2Class = "";
		if ($answer1Percent > $answer2Percent) {
			$answer1Class = "win";
			$answer2Class = "lose";
		} else if ($answer1Percent < $answer2Percent) {
			$answer1Class = "lose";
			$answer2Class = "win";
		} 
?>
<ul id="mytopic-<?php print $row["topicId"]; ?>" title="View"
		showToolbarButton="true" 
    toolbarButtonText="Delete" 
    toolbarButtonHREF="deletetopic.php?id=<?php print $_GET["id"]; ?>">
	<li class="heading">
		<?php print $row["question"]; ?><br />
  	<small>
      <?php print $row["categoryName"]; ?>
    	&nbsp;|&nbsp; Closed <?php print closingTimeFormat($row["dateClosed"]); ?>
    </small>
  </li>
	<li class="<?php print $answer1Class; ?>">
  	<div class="answer"><?php print $row["answer1"]; ?> <small>(<?php print $row["answer1Votes"]; ?>)</small></div>
    <div class="percent" style="width: <?php print $answer1Percent; ?>%;"><!-- --></div>
  </li>
	<li class="<?php print $answer2Class; ?>">
  	<div class="answer"><?php print $row["answer2"]; ?> <small>(<?php print $row["answer2Votes"]; ?>)</small></div>
    <div class="percent" style="width: <?php print $answer2Percent; ?>%;"><!-- --></div>
  </li>
</ul>
<?php
	}
?>

<?php 
	require_once("end.php"); 
?>